package com.gjy.vm.jli;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-06-02 11:41:09
 */
public class ClassFileTransformerImpl implements ClassFileTransformer {

    private static final Logger log = LoggerFactory.getLogger(ClassFileTransformerImpl.class);

    @Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                            ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
        /*log.info("class-name: {}", className);*/

        System.out.println("class-name: " + className);

        byte[] newClassfileBuffer = ClassBytecodeEnhancerImpl.enhanceClass(classfileBuffer);

        return newClassfileBuffer == null ? classfileBuffer : newClassfileBuffer;
    }
}
